//
//  ReleaseRateViewController.m
//  Logistics
//
//  Created by hy002 on 2018/1/23.
//  Copyright © 2018年 HUYU. All rights reserved.
//

#import "ReleaseRateViewController.h"
#import "ReleaseNotesViewController.h"
#import "ComLineModel.h"
#import "TruckTypeModel.h"
#import "LengthModel.h"
#import "CloseGoodsAddressViewController.h"

static NSString *cellPath = @"ReleaseRateCell";
@interface ReleaseRateViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,UIScrollViewDelegate,UIPickerViewDelegate,UIPickerViewDataSource>
{
    UIButton *leftBtn;
    UIButton *rightBtn;
    UIView *lineView;
    UIPickerView *pickTypeView;
}
@property (nonatomic, strong)UITableView *tableview;
@property (nonatomic, strong)NSString *lineName;
@property (nonatomic, strong)NSString *lineID;
@property (nonatomic, strong)UIView *TypeView;

@property (nonatomic, assign)NSInteger closeType;
@property (nonatomic, assign)BOOL isGx;
@property (nonatomic, strong)NSString *puLight;
@property (nonatomic, strong)NSString *puheavy;
@property (nonatomic, strong)NSString *putime;
@property (nonatomic, strong)NSString *kuaiLight;
@property (nonatomic, strong)NSString *kuaiheavy;
@property (nonatomic, strong)NSString *kuaitime;
@property (nonatomic, strong)NSString *shipmentID;
@property (nonatomic, strong)NSString *shipmentText;
@property (nonatomic, strong)NSString *destinationID;
@property (nonatomic, strong)NSString *destinationText;
@property (nonatomic, strong)NSString *truckName;
@property (nonatomic, strong)NSString *truckID;
@property (nonatomic, strong)NSString *lenthStr;
@property (nonatomic, strong)NSString *price;
@property (nonatomic, strong)NSArray *companyLineAry;
@property (nonatomic, assign)NSInteger rateType;
@property (nonatomic, assign)NSInteger TruckType;
@property (nonatomic, strong)NSArray *allTypeAry;

@end

@implementation ReleaseRateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _TruckType = 0;
    _lineName = @"线路选择";
    _lineID = @"";
    _puLight = @"";
    _puheavy = @"";
    _putime = @"";
    _kuaiLight = @"";
    _kuaiheavy = @"";
    _kuaitime = @"";
    _shipmentID = @"";
    _shipmentText = @"选择我将要卸货的地址";
    _destinationID = @"";
    _destinationText = @"选择我将要返回的地址";
    _truckName = @"";
    _truckID = @"";
    _lenthStr = @"";
    _price = @"";
    [self creatUI];
    [self requestCompanyLineMine];
    [self requestTruckType];
}

- (void)creatUI
{
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.translucent = NO;
    CGFloat H = 0;
    if (_isTrucks)
    {
        H = 45*displaywidth;
        self.navigationItem.title = @"线路管理";
        UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 45*displaywidth)];
        topView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:topView];
        leftBtn = [ZCControl createButtonWithFrame:CGRectMake(50*displaywidth, 0, SCREEN_WIDTH/2-50*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(leftAction) Title:@"零担价" Font:15.0];
        leftBtn.backgroundColor = [UIColor clearColor];
        [leftBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
        [topView addSubview:leftBtn];
        rightBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH/2, 0, SCREEN_WIDTH/2-50*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(rightAction) Title:@"整车价" Font:15.0];
        rightBtn.backgroundColor = [UIColor clearColor];
        [rightBtn setTitleColor:BlaTitColor forState:UIControlStateNormal];
        [topView addSubview:rightBtn];
        lineView = [[UIView alloc] initWithFrame:CGRectMake(50*displaywidth, 43.5*displaywidth, SCREEN_WIDTH/2-50*displaywidth, 1.5*displaywidth)];
        lineView.backgroundColor = ThemeColor;
        [topView addSubview:lineView];
        _closeType = 0;
        
    }
    else
    {
        self.navigationItem.title = @"整车价";
        _closeType = 1;
        
    }
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, H, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-H-65*displaywidth-SCREER_HeiX) style:UITableViewStylePlain];
    _tableview.backgroundColor = BacksColor;
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_tableview];
    UIButton *soureBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, SCREEN_HEIGHT-STA_NAV_HEIGHT-55*displaywidth-SCREER_HeiX, SCREEN_WIDTH-30*displaywidth, 45*displaywidth) ImageName:nil Target:self Action:@selector(soureBtnAction) Title:@"立即发布" Font:16.0];
    soureBtn.backgroundColor = RGB(255, 153, 0);
    [soureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    soureBtn.layer.cornerRadius = 5;
    soureBtn.layer.masksToBounds = YES;
    [self.view addSubview:soureBtn];
    
}

- (void)companyAction
{
    if (!self.TypeView)
    {
        self.TypeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT)];
        _TypeView.backgroundColor = RGBA(0, 0, 0, 0.6);
        [self.view addSubview:_TypeView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bottomViewPressed)];
        [_TypeView addGestureRecognizer:tap];
        pickTypeView = [[UIPickerView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-250*displayheight-STA_NAV_HEIGHT, SCREEN_WIDTH, 250*displayheight)];
        pickTypeView.backgroundColor = [UIColor whiteColor];
        pickTypeView.delegate = self;
        pickTypeView.dataSource = self;
        [_TypeView addSubview:pickTypeView];
        UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-280*displayheight-STA_NAV_HEIGHT, SCREEN_WIDTH, 30*displayheight)];
        whiteView.backgroundColor = [UIColor whiteColor];
        [_TypeView addSubview:whiteView];
        UIButton *cancelBtn = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, 10*displayheight, 40*displaywidth, 20*displayheight) ImageName:nil Target:self Action:@selector(bottomViewPressed) Title:@"取消" Font:13.0];
        cancelBtn.backgroundColor = ThemeColor;
        [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        cancelBtn.layer.cornerRadius = 3;
        cancelBtn.layer.masksToBounds = YES;
        [whiteView addSubview:cancelBtn];
        
        UIButton *soureBtn = [ZCControl createButtonWithFrame:CGRectMake(SCREEN_WIDTH- 55*displaywidth, 10*displayheight, 40*displaywidth, 20*displayheight) ImageName:nil Target:self Action:@selector(soureAction) Title:@"确定" Font:13.0];
        soureBtn.backgroundColor = ThemeColor;
        [soureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        soureBtn.layer.cornerRadius = 3;
        soureBtn.layer.masksToBounds = YES;
        [whiteView addSubview:soureBtn];
        
    }
    _TypeView.hidden = NO;
    
}

- (void)soureAction
{
    NSInteger selectRow = [pickTypeView selectedRowInComponent:0];
    if (_rateType == 0)
    {
        ComLineModel *model = _companyLineAry[selectRow];
        _lineName = [NSString stringWithFormat:@"%@->%@",model.shipmentName,model.destinationname];
        _shipmentID = s_str(model.shipmentID);
        _destinationID = s_str(model.destinationID);
        _lineID = s_str(model.ID);
    }
    else if (_rateType == 1)
    {
        TruckTypeModel *model = _allTypeAry[selectRow];
        _truckName = model.name;
        _truckID = s_str(model.ID);
        if (_TruckType != (selectRow+1))
        {
            _lenthStr = @"";
        }
        _TruckType = selectRow+1;
    }
    else if (_rateType == 2)
    {
        TruckTypeModel *model = _allTypeAry[_TruckType-1];
        NSArray *lenthAry = model.truckLengths;
        LengthModel *lenModel = lenthAry[selectRow];
        _lenthStr = lenModel.length;
    }
    [self bottomViewPressed];
    [_tableview reloadData];
}


- (void)bottomViewPressed
{
    _TypeView.hidden = YES;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

//指定每个表盘上有几行数据
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (_rateType == 0)
    {
        return _companyLineAry.count;
    }
    else if (_rateType == 2)
    {
        TruckTypeModel *model = _allTypeAry[_TruckType-1];
        NSArray *lenthAry = model.truckLengths;
        return lenthAry.count;
    }
    else
    {
        return _allTypeAry.count;
    }
}

#pragma mark UIPickerView Delegate Method 代理方法

//指定每行如何展示数据（此处和tableview类似）
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (_rateType == 0)
    {
        ComLineModel *model = _companyLineAry[row];
        return [NSString stringWithFormat:@"%@->%@",model.shipmentName,model.destinationname];
    }
    else if (_rateType == 2)
    {
        TruckTypeModel *model = _allTypeAry[_TruckType-1];
        NSArray *lenthAry = model.truckLengths;
        LengthModel *lenModel = lenthAry[row];
        return lenModel.length;
    }
    else
    {
        TruckTypeModel *model = _allTypeAry[row];
        return model.name;
    }
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSLog(@"%ld------%ld",component,row);
}



- (void)leftAction
{
    if (_closeType != 0)
    {
        [self.view endEditing:YES];
        _closeType = 0;
        _shipmentID = @"";
        _destinationID = @"";
        [leftBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
        [rightBtn setTitleColor:BlaTitColor forState:UIControlStateNormal];
        lineView.frame = CGRectMake(50*displaywidth, 43.5*displaywidth, SCREEN_WIDTH/2-50*displaywidth, 1.5*displaywidth);
        [_tableview reloadData];
    }
    
}

- (void)rightAction
{
    if (_closeType != 1)
    {
        [self.view endEditing:YES];
        _closeType = 1;
        _shipmentID = @"";
        _destinationID = @"";
        [rightBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
        [leftBtn setTitleColor:BlaTitColor forState:UIControlStateNormal];
        lineView.frame = CGRectMake(SCREEN_WIDTH/2, 43.5*displaywidth, SCREEN_WIDTH/2-50*displaywidth, 1.5*displaywidth);
        [_tableview reloadData];
    }
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0 && _closeType == 1)
    {
        return 2;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellPath];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor whiteColor];
    if (indexPath.row == 0 && indexPath.section != 2)
    {
        UIView *grayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10*displaywidth)];
        grayView.backgroundColor = BacksColor;
        [cell.contentView addSubview:grayView];
    }
    if (_closeType == 0)
    {
        if (indexPath.section == 0)
        {
            UIImageView *imageAview = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, 20*displaywidth, 25*displaywidth, 25*displaywidth) ImageName:@"sy_icon03"];
            imageAview.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:imageAview];
            UILabel *lineNameLab = [ZCControl createLabelWithFrame:CGRectMake(45*displaywidth, 15*displaywidth, SCREEN_WIDTH-85*displaywidth, 35*displaywidth) Font:16.0 Text:_lineName Color:BlaTitColor];
            [cell.contentView addSubview:lineNameLab];
            UIImageView *imgV = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-30*displaywidth, 25*displayheight, 15*displaywidth, 15*displayheight) ImageName:@"gs_icon05"];
            imgV.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:imgV];
        }
        else if (indexPath.section == 1)
        {
            UIView *puView = [[UIView alloc] initWithFrame:CGRectMake(25*displaywidth, 35*displaywidth, SCREEN_WIDTH-50*displaywidth, 126*displaywidth)];
            puView.layer.cornerRadius = 3;
            puView.layer.masksToBounds = YES;
            puView.layer.borderWidth = 1;
            puView.layer.borderColor = RGB(204, 204, 204).CGColor;
            [cell.contentView addSubview:puView];
            UILabel *puLab = [ZCControl createLabelWithFrame:CGRectMake(5*displaywidth, 5*displaywidth, 35*displaywidth, 115*displaywidth) Font:15.0 Text:@"普\n运" Color:ThemeColor];
            puLab.textAlignment = NSTextAlignmentCenter;
            [puView addSubview:puLab];
            NSArray *titAry = @[@"轻货",@"重货",@"时效"];
            NSArray *pladerAry = @[@"元/方",@"元/吨",@"如：1-3 /天"];
            NSArray *puAry = @[_puLight,_puheavy,_putime];
            for (int i = 0; i < 3; i++)
            {
                UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(45*displaywidth, 42*displaywidth*i, 45*displaywidth, 42*displaywidth) Font:14.0 Text:titAry[i] Color:BlaTitColor];
                titLab.textAlignment = NSTextAlignmentCenter;
                [puView addSubview:titLab];
                UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(100*displaywidth,42*displaywidth*i+3*displaywidth, SCREEN_WIDTH-160*displaywidth, 35*displaywidth) placeholder:pladerAry[i] passWord:NO leftImageView:nil rightImageView:nil Font:14.0];
                [textfield setValue:RGB(204, 204, 204) forKeyPath:@"_placeholderLabel.textColor"];
                textfield.delegate = self;
                textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
                textfield.textColor = BlaTitColor;
                textfield.textAlignment = NSTextAlignmentRight;
                textfield.text = puAry[i];
                textfield.tag = 100+i;
                [puView addSubview:textfield];
                UIView *alineView = [[UIView alloc] initWithFrame:CGRectMake(45*displaywidth, 42*displaywidth*i, 1*displaywidth, 42*displaywidth)];
                alineView.backgroundColor = RGB(204, 204, 204);
                [puView addSubview:alineView];
                
                UIView *blineView = [[UIView alloc] initWithFrame:CGRectMake(90*displaywidth, 42*displaywidth*i+13*displaywidth, 1*displaywidth, 16*displaywidth)];
                blineView.backgroundColor = RGB(204, 204, 204);
                [puView addSubview:blineView];
                if (i != 0)
                {
                    UIView *clineView = [[UIView alloc] initWithFrame:CGRectMake(45*displaywidth, 42*displaywidth*i, SCREEN_WIDTH-95*displaywidth, 1*displaywidth)];
                    clineView.backgroundColor = RGB(204, 204, 204);
                    [puView addSubview:clineView];
                }
            }
            
            UIView *kuaiView = [[UIView alloc] initWithFrame:CGRectMake(25*displaywidth, 180*displaywidth, SCREEN_WIDTH-50*displaywidth, 126*displaywidth)];
            kuaiView.layer.cornerRadius = 3;
            kuaiView.layer.masksToBounds = YES;
            kuaiView.layer.borderWidth = 1;
            kuaiView.layer.borderColor = RGB(204, 204, 204).CGColor;
            [cell.contentView addSubview:kuaiView];
            UILabel *kuaiLab = [ZCControl createLabelWithFrame:CGRectMake(5*displaywidth, 5*displaywidth, 35*displaywidth, 115*displaywidth) Font:15.0 Text:@"快\n运" Color:ThemeColor];
            kuaiLab.textAlignment = NSTextAlignmentCenter;
            [kuaiView addSubview:kuaiLab];
            NSArray *kuaiAry = @[_kuaiLight,_kuaiheavy,_kuaitime];
            for (int i = 0; i < 3; i++)
            {
                UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(45*displaywidth, 42*displaywidth*i, 45*displaywidth, 42*displaywidth) Font:14.0 Text:titAry[i] Color:BlaTitColor];
                titLab.textAlignment = NSTextAlignmentCenter;
                [kuaiView addSubview:titLab];
                UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(100*displaywidth,42*displaywidth*i+3*displaywidth, SCREEN_WIDTH-160*displaywidth, 35*displaywidth) placeholder:pladerAry[i] passWord:NO leftImageView:nil rightImageView:nil Font:14.0];
                [textfield setValue:RGB(204, 204, 204) forKeyPath:@"_placeholderLabel.textColor"];
                textfield.delegate = self;
                textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
                textfield.textColor = BlaTitColor;
                textfield.textAlignment = NSTextAlignmentRight;
                textfield.text = kuaiAry[i];
                textfield.tag = 200+i;
                [kuaiView addSubview:textfield];
                UIView *alineView = [[UIView alloc] initWithFrame:CGRectMake(45*displaywidth, 42*displaywidth*i, 1*displaywidth, 42*displaywidth)];
                alineView.backgroundColor = RGB(204, 204, 204);
                [kuaiView addSubview:alineView];
                
                UIView *blineView = [[UIView alloc] initWithFrame:CGRectMake(90*displaywidth, 42*displaywidth*i+13*displaywidth, 1*displaywidth, 16*displaywidth)];
                blineView.backgroundColor = RGB(204, 204, 204);
                [kuaiView addSubview:blineView];
                if (i != 0)
                {
                    UIView *clineView = [[UIView alloc] initWithFrame:CGRectMake(45*displaywidth, 42*displaywidth*i, SCREEN_WIDTH-95*displaywidth, 1*displaywidth)];
                    clineView.backgroundColor = RGB(204, 204, 204);
                    [kuaiView addSubview:clineView];
                }
            }

        }
    }
    else
    {
        if (indexPath.section == 0)
        {
            NSArray *imgAry = @[@"congicon",@"huiicon"];
            CGFloat height = 0;
            if (indexPath.row == 0)
            {
                height = 10*displaywidth;
            }
            UIImageView *imgView = [ZCControl createImageViewWithFrame:CGRectMake(15*displaywidth, height+17.5*displaywidth, 20*displaywidth, 25*displaywidth) ImageName:imgAry[indexPath.row]];
            imgView.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:imgView];
            NSArray *textAry = @[_shipmentText,_destinationText];
            NSArray *pladerAry = @[_shipmentID,_destinationID];
            UILabel *textLab = [ZCControl createLabelWithFrame:CGRectMake(50*displaywidth, height+10*displaywidth, SCREEN_WIDTH-80*displaywidth, 40*displaywidth) Font:17.0 Text:textAry[indexPath.row] Color:RGB(204, 204, 204)];
            if (![pladerAry[indexPath.row] isEqualToString:@""])
            {
                textLab.textColor = BlaTitColor;
            }
            [cell.contentView addSubview:textLab];
            if (indexPath.row == 0)
            {
                UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(50*displaywidth, height+59*displaywidth, SCREEN_WIDTH-65*displaywidth, 1*displaywidth)];
                lineView.backgroundColor = RGB(204, 204, 204);
                [cell.contentView addSubview:lineView];
            }
            UIImageView *imgV = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-30*displaywidth, height+20*displayheight, 15*displaywidth, 20*displayheight) ImageName:@"gs_icon05"];
            imgV.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:imgV];
        }
        else if (indexPath.section == 1)
        {
            UIView *carInfoView = [[UIView alloc] initWithFrame:CGRectMake(25*displaywidth, 35*displaywidth, SCREEN_WIDTH-50*displaywidth, 84*displaywidth)];
            carInfoView.layer.cornerRadius = 3;
            carInfoView.layer.masksToBounds = YES;
            carInfoView.layer.borderWidth = 1;
            carInfoView.layer.borderColor = RGB(204, 204, 204).CGColor;
            [cell.contentView addSubview:carInfoView];
            UILabel *puLab = [ZCControl createLabelWithFrame:CGRectMake(5*displaywidth, 0, 35*displaywidth, 84*displaywidth) Font:14.0 Text:@"车\n辆\n信\n息" Color:ThemeColor];
            puLab.textAlignment = NSTextAlignmentCenter;
            [carInfoView addSubview:puLab];
            NSArray *titAry = @[@"车型",@"车长"];
            NSArray *puAry = @[_truckName,_lenthStr];
            for (int i = 0; i < 2; i++)
            {
                UILabel *titLab = [ZCControl createLabelWithFrame:CGRectMake(45*displaywidth, 42*displaywidth*i, 45*displaywidth, 42*displaywidth) Font:14.0 Text:titAry[i] Color:BlaTitColor];
                titLab.textAlignment = NSTextAlignmentCenter;
                [carInfoView addSubview:titLab];
                UILabel *closeLab = [ZCControl createLabelWithFrame:CGRectMake(100*displaywidth,42*displaywidth*i+3*displaywidth, SCREEN_WIDTH-160*displaywidth, 35*displaywidth) Font:14.0 Text:puAry[i] Color:BlaTitColor];
                [carInfoView addSubview:closeLab];
                UIImageView *imgV = [ZCControl createImageViewWithFrame:CGRectMake(SCREEN_WIDTH-80*displaywidth, 42*displaywidth*i+11*displayheight, 15*displaywidth, 20*displayheight) ImageName:@"gs_icon05"];
                imgV.contentMode = UIViewContentModeScaleAspectFit;
                [carInfoView addSubview:imgV];
                UIView *alineView = [[UIView alloc] initWithFrame:CGRectMake(45*displaywidth, 42*displaywidth*i, 1*displaywidth, 42*displaywidth)];
                alineView.backgroundColor = RGB(204, 204, 204);
                [carInfoView addSubview:alineView];
                
                UIView *blineView = [[UIView alloc] initWithFrame:CGRectMake(90*displaywidth, 42*displaywidth*i+13*displaywidth, 1*displaywidth, 16*displaywidth)];
                blineView.backgroundColor = RGB(204, 204, 204);
                [carInfoView addSubview:blineView];
                if (i != 0)
                {
                    UIView *clineView = [[UIView alloc] initWithFrame:CGRectMake(45*displaywidth, 42*displaywidth*i, SCREEN_WIDTH-95*displaywidth, 1*displaywidth)];
                    clineView.backgroundColor = RGB(204, 204, 204);
                    [carInfoView addSubview:clineView];
                }
                UIButton *btn = [ZCControl createButtonWithFrame:CGRectMake(100*displaywidth,42*displaywidth*i+3*displaywidth, SCREEN_WIDTH-160*displaywidth, 35*displaywidth) ImageName:nil Target:self Action:@selector(closeCarInfoAction:) Title:nil Font:12.0];
                btn.backgroundColor = [UIColor clearColor];
                btn.tag = 600+i;
                [carInfoView addSubview:btn];
            }
            UIView *priceView = [[UIView alloc] initWithFrame:CGRectMake(25*displaywidth, 135*displaywidth, SCREEN_WIDTH-50*displaywidth, 42*displaywidth)];
            priceView.layer.cornerRadius = 3;
            priceView.layer.masksToBounds = YES;
            priceView.layer.borderWidth = 1;
            priceView.layer.borderColor = RGB(204, 204, 204).CGColor;
            [cell.contentView addSubview:priceView];
            
            UILabel *titALab = [ZCControl createLabelWithFrame:CGRectMake(0, 0, 45*displaywidth, 42*displaywidth) Font:14.0 Text:@"运价" Color:BlaTitColor];
            titALab.textAlignment = NSTextAlignmentCenter;
            [priceView addSubview:titALab];
            UIView *dlineView = [[UIView alloc] initWithFrame:CGRectMake(45*displaywidth, 13*displaywidth, 1*displaywidth, 16*displaywidth)];
            dlineView.backgroundColor = RGB(204, 204, 204);
            [priceView addSubview:dlineView];
            UITextField *textfield = [ZCControl createTextFieldWithFrame:CGRectMake(50*displaywidth, 3*displaywidth, SCREEN_WIDTH-110*displaywidth, 35*displaywidth) placeholder:@"/元" passWord:NO leftImageView:nil rightImageView:nil Font:14.0];
            [textfield setValue:RGB(204, 204, 204) forKeyPath:@"_placeholderLabel.textColor"];
            textfield.delegate = self;
            textfield.clearButtonMode = UITextFieldViewModeWhileEditing;
            textfield.textColor = BlaTitColor;
            textfield.textAlignment = NSTextAlignmentRight;
            textfield.text = _price;
            textfield.tag = 500;
            [priceView addSubview:textfield];
        }
    }
    if (indexPath.section == 2)
    {
        cell.backgroundColor = BacksColor;
        NSString *imgStr = @"gouxuan1";
        if (_isGx)
        {
            imgStr = @"gouxuan2";
        }
        UIButton *gouXuan = [ZCControl createButtonWithFrame:CGRectMake(15*displaywidth, 15*displaywidth, 200*displaywidth, 20*displaywidth) ImageName:imgStr Target:self Action:@selector(gouxuanAction:) Title:@" 承诺此信息真实，不虚假" Font:12.0];
        [gouXuan setTitleColor:RGB(174, 174, 174) forState:UIControlStateNormal];
        gouXuan.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        gouXuan.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        NSString *content = gouXuan.titleLabel.text;
        UIFont *font = gouXuan.titleLabel.font;
        CGSize size = CGSizeMake(MAXFLOAT, 20*displaywidth);
        CGSize buttonSize = [content boundingRectWithSize:size
                                                  options:NSStringDrawingTruncatesLastVisibleLine  | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
                                               attributes:@{ NSFontAttributeName:font}
                                                  context:nil].size;
        gouXuan.frame = CGRectMake(15*displaywidth, 15*displaywidth, buttonSize.width+30*displaywidth, 20*displaywidth);
        [cell.contentView addSubview:gouXuan];
        UIButton *xzBtn = [ZCControl createButtonWithFrame:CGRectMake(buttonSize.width+45*displaywidth, 15*displaywidth, 100*displaywidth, 20*displaywidth) ImageName:nil Target:self Action:@selector(xieyiAction) Title:@"《发布须知》" Font:12.0];
        [xzBtn setTitleColor:ThemeColor forState:UIControlStateNormal];
        xzBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        xzBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [cell.contentView addSubview:xzBtn];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_closeType == 0 && indexPath.section == 0)
    {
        _rateType = 0;
        [self companyAction];
        [pickTypeView reloadAllComponents];
    }
    else if (_closeType == 1 && indexPath.section == 0)
    {
        WEAKSELF;
        CloseGoodsAddressViewController *vc = [[CloseGoodsAddressViewController alloc] init];
        vc.areaType = indexPath.row;
        vc.isPush = YES;
        vc.closeBlock = ^(NSString *name, NSInteger index)
        {
            NSArray *nameAry = [name componentsSeparatedByString:@","];
            if (nameAry.count == 2)
            {
                if (index == 0)
                {
                    _shipmentText = nameAry[0];
                    _shipmentID = nameAry[1];
                }
                else
                {
                    _destinationText = nameAry[0];
                    _destinationID = nameAry[1];
                }
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf.tableview reloadData];
            });
        };
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)closeCarInfoAction:(UIButton *)btn
{
    if (btn.tag == 600)
    {
        _rateType = 1;
        
    }
    else
    {
        if (_TruckType == 0)
        {
            [LTools showMBProgressWithText:@"请先选择车型" addToView:self.view];
            return;
        }
        _rateType = 2;
    }
    [self companyAction];
    [pickTypeView reloadAllComponents];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_closeType == 0)
    {
        if (indexPath.section == 0)
        {
            return 55*displaywidth;
        }
        else if (indexPath.section == 1)
        {
            return 330*displaywidth;
        }
        else
        {
            return 50*displaywidth;
        }
        
    }
    else
    {
        if (indexPath.section == 0)
        {
            if (indexPath.row == 0)
            {
                return 70*displaywidth;
            }
            return 60*displaywidth;
        }
        else if (indexPath.section == 1)
        {
            return 200*displaywidth;
        }
        else
        {
            return 50*displaywidth;
        }
    }
}

- (void)gouxuanAction:(UIButton *)btn
{
    _isGx = !_isGx;
    NSString *imgStr = @"gouxuan1";
    if (_isGx)
    {
        imgStr = @"gouxuan2";
    }
    [btn setImage:IMAGE(imgStr) forState:UIControlStateNormal];
    [btn setTitle:@" 承诺此信息真实，不虚假" forState:UIControlStateNormal];
}

//发布须知
- (void)xieyiAction
{
    ReleaseNotesViewController *vc = [[ReleaseNotesViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)soureBtnAction
{
    [self.view endEditing:YES];
    NSDictionary *dic;
    if (_closeType == 0)
    {
        NSArray *nameARRAY = @[_lineID,_puLight,_puheavy,_putime,_kuaiLight,_kuaiheavy,_kuaitime];
        NSArray *tostAry = @[@"请选择线路",@"请输入普运轻货单价",@"请输入普运重货单价",@"请输入普运时效",@"请输入快运轻货单价",@"请输入快运重货单价",@"请输入快运时效"];
        for (int i = 0; i < nameARRAY.count; i++)
        {
            if ([nameARRAY[i] isEqualToString:@""])
            {
                [LTools showMBProgressWithText:tostAry[i] addToView:self.view];
                return;
            }
        }
        if (!_isGx)
        {
            [LTools showMBProgressWithText:@"请勾选承诺信息" addToView:self.view];
            return;
        }
        dic = @{@"companyLine.id":_lineID,
                @"pLowPrice":_puLight,
                @"pHeavyPrice":_puheavy,
                @"pTimeBar":_putime,
                @"kLowPrice":_kuaiLight,
                @"kHeavyPrice":_kuaiheavy,
                @"kTimeBar":_kuaitime,
                @"destination.id":_destinationID,
                @"shipment.id":_shipmentID,
                @"type":s_Integer(_closeType+1)};
    }
    else
    {
        NSArray *nameARRAY = @[_shipmentID,_destinationID,_truckID,_lenthStr,_price];
        NSArray *tostAry = @[@"请选择将要卸货的地址",@"请选择将要返回的地址",@"请选择车型",@"请选择车长",@"请输入运价"];
        for (int i = 0; i < nameARRAY.count; i++)
        {
            if ([nameARRAY[i] isEqualToString:@""])
            {
                [LTools showMBProgressWithText:tostAry[i] addToView:self.view];
                return;
            }
        }
        if (!_isGx)
        {
            [LTools showMBProgressWithText:@"请勾选承诺信息" addToView:self.view];
            return;
        }
        dic = @{@"price":_price,
                @"truckTypeId":_truckID,
                @"truckType":_truckName,
                @"length":_lenthStr,
                @"destination.id":_destinationID,
                @"shipment.id":_shipmentID,
                @"type":s_Integer(_closeType+1)};
    }
    
    WEAKSELF;
    [HYBaseHandler requestWithTheFormUrl:SERVER_companyLineSave Parmers:dic Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             [LTools showMBProgressWithText:@"发布成功" addToView:sharedDelegate.window];
             [self.navigationController popViewControllerAnimated:YES];
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         
     }];
}


- (void)requestCompanyLineMine
{
    WEAKSELF;
    NSDictionary *dic = @{@"size":@"9999"};
    [HYBaseHandler requestWithTheFormUrl:SERVER_companyLineMine Parmers:dic Success:^(id obj) {
        if ([obj server_Getcodecheck])
        {
            _companyLineAry = [ComLineModel mj_objectArrayWithKeyValuesArray:obj[@"data"][@"content"]];
        }
        else
        {
            [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
        }
    } failed:^(NSError *error) {
       
    }];
}

- (void)requestTruckType
{
    WEAKSELF;
    [HYBaseHandler requestWithTheFormUrl:SERVER_truckType Parmers:nil Success:^(id obj)
     {
         if ([obj server_Getcodecheck])
         {
             _allTypeAry = [TruckTypeModel mj_objectArrayWithKeyValuesArray:obj[@"data"]];
             dispatch_async(dispatch_get_main_queue(), ^{
                 
                 [weakSelf.tableview reloadData];
             });
         }
         else
         {
             [LTools showMBProgressWithText:obj[@"msg"] addToView:weakSelf.view];
         }
     } failed:^(NSError *error) {
         
     }];
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField.tag == 201)
    {
        _tableview.frame = CGRectMake(0, -100*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-110*displaywidth-SCREER_HeiX);
    }
    else if (textField.tag == 202)
    {
        _tableview.frame = CGRectMake(0, -100*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-110*displaywidth-SCREER_HeiX);
        
    }
    else if (textField.tag == 500)
    {
        _tableview.frame = CGRectMake(0, -100*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-65*displaywidth-SCREER_HeiX);
        
    }
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (textField.tag == 100)
    {
        _puLight = textField.text;
    }
    else if (textField.tag == 101)
    {
        _puheavy = textField.text;
    }
    else if (textField.tag == 102)
    {
        _putime = textField.text;
    }
    else if (textField.tag == 200)
    {
        _kuaiLight = textField.text;
    }
    else if (textField.tag == 201)
    {
        _kuaiheavy = textField.text;
        _tableview.frame = CGRectMake(0, 45*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-110*displaywidth-SCREER_HeiX);
    }
    else if (textField.tag == 202)
    {
        _kuaitime = textField.text;
        _tableview.frame = CGRectMake(0, 45*displaywidth, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-110*displaywidth-SCREER_HeiX);

    }
    else if (textField.tag == 500)
    {
        _price = textField.text;
        _tableview.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-STA_NAV_HEIGHT-65*displaywidth-SCREER_HeiX);

    }
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
    
}

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.view endEditing:YES];
    return indexPath;
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.view endEditing:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
